<?php
/**
 * Created by PhpStorm.
 * User: UEWARE
 * Date: 2019-9-6
 * Time: 17:00:56
 */

namespace App\Http\Controllers\WeChat\Diary\V1\User;

use App\Http\Controllers\WeChat\WeChatController;
use App\Models\TravelsContentModel;
use App\Models\TravelsModel;
use Illuminate\Http\Request;

class TravelsDetailController extends WeChatController
{
    /**
     * 用户详情列表
     *
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(Request $request)
    {
        // 获取
        $data = $request->only('id');

        if (empty($data['id'])) {
            return error(800001);
        }

        $list = TravelsModel::query()
            ->where('id', $data['id'])
            ->first()
            ->toArray();

        $content = TravelsContentModel::query()
            ->where('t_id', $data['id'])
            ->get()
            ->toArray();

        foreach ($content as &$val) {
            $val['poi'] = json_decode($val['address'], true);
            unset($val['address']);
        }

        return success(['list' => $content, 'meta' => $list]);
    }
}
